
package com.hisense.settings;

import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import com.android.settings.R;
import java.util.List;
import android.util.Log;

import com.hisense.settings.device.PairingDevice;

import com.hisense.settings.util.Wrapper;
/*import com.marvell.tv.TVAVSettingsConstants.TvSource;
import com.marvell.willowtv.framework.util.atsc.InputSourceType;
import com.marvell.willowtv.framework.features.ParentalControl;
import com.marvell.willowtv.framework.util.atsc.ChannelEnumClass.DeviceModificationFlags;
import com.marvell.willowtv.framework.features.TvFramework;*/
import java.util.ArrayList;

public class MyCheck extends PreferenceActivity implements Preference.OnPreferenceChangeListener {

    private static final String TAG = "MyCheck";

    private static final String KEY_SET_TUNER = "set_tuner";
    private static final String KEY_SET_COMPOSITE = "set_composite";
    private static final String KEY_SET_COMPONENT = "set_component";
    private static final String KEY_SET_VGA = "set_vga";
    private static final String KEY_SET_HDMI_1 = "set_hdmi1";
    private static final String KEY_SET_HDMI_2 = "set_hdmi2";
    private static final String KEY_SET_HDMI_3 = "set_hdmi3";
    private static final String KEY_SET_HDMI_4 = "set_hdmi4";

    private static CheckBoxPreference mSetTuner;
    private static CheckBoxPreference mSetComposite;
    private static CheckBoxPreference mSetComponent;
    private static CheckBoxPreference mSetVga;
    private static CheckBoxPreference mSet_HDMI_1;
    private static CheckBoxPreference mSet_HDMI_2;
    private static CheckBoxPreference mSet_HDMI_3;
    private static CheckBoxPreference mSet_HDMI_4;
    //private final ParentalControl mParentalControl = TvFramework.getInstance()
    //        .getParentalControlInstance();
    private int mSelectedId = 0;
    public static int click_flag = 0;

    @SuppressWarnings("serial")
    public static List<String> mDevIdList = new ArrayList<String>() {

        {
            add(PairingDevice.TUNER_DEVICE_ID);
            add(PairingDevice.COMPOSITE_DEVICE_ID);
            add(PairingDevice.COMPONENT_DEVICE_ID);
            add(PairingDevice.VGA_DEVICE_ID);
            add(PairingDevice.HDMI1_DEVICE_ID);
            add(PairingDevice.HDMI2_DEVICE_ID);
            add(PairingDevice.HDMI3_DEVICE_ID);
            add(PairingDevice.HDMI4_DEVICE_ID);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.setting_parental_lock_input);
        mSetTuner = (CheckBoxPreference) findPreference(KEY_SET_TUNER);
        mSetTuner.setOnPreferenceChangeListener(this);

        mSetComposite = (CheckBoxPreference) findPreference(KEY_SET_COMPOSITE);
        mSetComposite.setOnPreferenceChangeListener(this);

        mSetComponent = (CheckBoxPreference) findPreference(KEY_SET_COMPONENT);
        mSetComponent.setOnPreferenceChangeListener(this);

        mSetVga = (CheckBoxPreference) findPreference(KEY_SET_VGA);
        mSetVga.setOnPreferenceChangeListener(this);

        mSet_HDMI_1 = (CheckBoxPreference) findPreference(KEY_SET_HDMI_1);
        mSet_HDMI_1.setOnPreferenceChangeListener(this);

        mSet_HDMI_2 = (CheckBoxPreference) findPreference(KEY_SET_HDMI_2);
        mSet_HDMI_2.setOnPreferenceChangeListener(this);

        mSet_HDMI_3 = (CheckBoxPreference) findPreference(KEY_SET_HDMI_3);
        mSet_HDMI_3.setOnPreferenceChangeListener(this);

        mSet_HDMI_4 = (CheckBoxPreference) findPreference(KEY_SET_HDMI_4);
        mSet_HDMI_4.setOnPreferenceChangeListener(this);
    

    }

    @Override
    public void onResume() {
        super.onResume();
		int currentSource=0;
		int serviceFlag = 1;
		currentSource = getSelectedInputSource(0);
        //serviceFlag = mParentalControl.getDeviceInputStatus(currentSource);
		if(serviceFlag == 0)
		mSetTuner.setChecked(false);
		else
		mSetTuner.setChecked(true);

		currentSource = getSelectedInputSource(1);
        //serviceFlag = mParentalControl.getDeviceInputStatus(currentSource);
		if(serviceFlag == 0)
		mSetComposite.setChecked(false);
		else
		mSetComposite.setChecked(true);

		currentSource = getSelectedInputSource(2);
        //serviceFlag = mParentalControl.getDeviceInputStatus(currentSource);
		if(serviceFlag == 0)
		mSetComponent.setChecked(false);
		else
		mSetComponent.setChecked(true);

		currentSource = getSelectedInputSource(3);
        //serviceFlag = mParentalControl.getDeviceInputStatus(currentSource);
		if(serviceFlag == 0)
		mSetVga.setChecked(false);
		else
		mSetVga.setChecked(true);

		currentSource = getSelectedInputSource(4);
        //serviceFlag = mParentalControl.getDeviceInputStatus(currentSource);
		if(serviceFlag == 0)
		mSet_HDMI_1.setChecked(false);
		else
		mSet_HDMI_1.setChecked(true);

		currentSource = getSelectedInputSource(5);
        //serviceFlag = mParentalControl.getDeviceInputStatus(currentSource);
		if(serviceFlag == 0)
		mSet_HDMI_2.setChecked(false);
		else
		mSet_HDMI_2.setChecked(true);

		currentSource = getSelectedInputSource(6);
        //serviceFlag = mParentalControl.getDeviceInputStatus(currentSource);
		if(serviceFlag == 0)
		mSet_HDMI_3.setChecked(false);
		else
		mSet_HDMI_3.setChecked(true);

		currentSource = getSelectedInputSource(7);
        //serviceFlag = mParentalControl.getDeviceInputStatus(currentSource);
		if(serviceFlag == 0)
		mSet_HDMI_4.setChecked(false);
		else
		mSet_HDMI_4.setChecked(true);

    }

    @Override
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {

        Log.d(TAG, "----33333333333333333333------ key---:");
        return false;
    }

    private void showResult(String strKey, Boolean value) {

        if (strKey.equals(KEY_SET_TUNER)) {
            mSelectedId = 0;
        }
        if (strKey.equals(KEY_SET_COMPOSITE)) {
            mSelectedId = 1;
        }
        if (strKey.equals(KEY_SET_COMPONENT)) {
            mSelectedId = 2;
        }
        if (strKey.equals(KEY_SET_VGA)) {
            mSelectedId = 3;
        }
        if (strKey.equals(KEY_SET_HDMI_1)) {
            mSelectedId = 4;
        }
        if (strKey.equals(KEY_SET_HDMI_2)) {
            mSelectedId = 5;
        }
        if (strKey.equals(KEY_SET_HDMI_3)) {
            mSelectedId = 6;
        }
        if (strKey.equals(KEY_SET_HDMI_4)) {
            mSelectedId = 7;
        }
        Wrapper.getWrapperInstance().setPCEnable(1);

        int currentSource = getSelectedInputSource(mSelectedId);
        //int serviceFlag = mParentalControl.getDeviceInputStatus(currentSource);
        //serviceFlag = serviceFlag ^ DeviceModificationFlags.Lock_Flag;
        //mParentalControl.setDeviceInputStatus(currentSource, serviceFlag);
        //Log.d(TAG, "---show result-----currentSource:"+currentSource+",,serviceFlag:"+serviceFlag);
    }

    public boolean onPreferenceChange(Preference preference, Object objValue) {
        final String key = preference.getKey();
        boolean value = (Boolean) objValue;
        mycheck_click_flag();

        showResult(key, value);

        return true;
    }

    public int getSelectedInputSource(int selectedid) {
        /*return ((TvSource) PairingDevice.DeviceIdSourceMap.get(MyCheck.mDevIdList.get(selectedid)))
                .value();*/
        return 0;
    }

    public boolean isDeviceLocked(int deviceFlag) {
        /*if ((deviceFlag & DeviceModificationFlags.Lock_Flag) == DeviceModificationFlags.Lock_Flag) {
            return true;
        }*/
        return false;
    }

    public static void clear_mycheck() {
        mSetComposite.setChecked(false);
        mSetTuner.setChecked(false);
        mSetComponent.setChecked(false);
        mSetVga.setChecked(false);

        mSet_HDMI_1.setChecked(false);
        mSet_HDMI_2.setChecked(false);
        mSet_HDMI_3.setChecked(false);
        mSet_HDMI_4.setChecked(false);

        Log.d(TAG, "---clear_mycheck-----:");
    }

    public static void mycheck_click_flag() {
        click_flag = 1;
        Log.d(TAG, "---mycheck_click_flag---------:");
    }

}
